package com.sspaas.generator;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

public class GeneratorUtils {
	//
	public static void main(String[] args) {
		try {
			List<String> warnings = new ArrayList<String>();
			//加载配置文件
			File configFile = new File("src/main/resources/generator-mysql.xml");
			//解析器
			ConfigurationParser parse = new ConfigurationParser(warnings);
			//解析文件
			Configuration config = parse.parseConfiguration(configFile);
			DefaultShellCallback callback = new DefaultShellCallback(true);
			
			MyBatisGenerator mybatis = new MyBatisGenerator(config, callback, warnings);
			mybatis.generate(null);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XMLParserException e) {
			e.printStackTrace();
		} catch (InvalidConfigurationException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("---------------success--------------");
	}
}
